package dao.impl;

import dao.AccountDao;
import entity.Account;

import java.sql.Timestamp;

public class AccountDaoImpl extends BaseDao implements AccountDao {
    @Override
    public int addAccount(Account account) throws Exception{
        connection=getConnection();
        String sql = "insert into account values (sq_account.nextval,?,?,?,?,?,?)";
        Object[] objects=new Object[6];
        objects[0]=account.getDealType();
        objects[1]= account.getPetId();
        objects[2]= account.getSellerId();
        objects[3]= account.getBuyerId();
        objects[4]= account.getPrice();
        Timestamp timestamp = new Timestamp(account.getDealTime().getTime());
        objects[5]= timestamp;
        int update = update(sql, objects);
        close(resultSet,statement,connection);
        return update;
    }

    @Override
    public int changeAccount(Account account) throws Exception {
        connection=getConnection();
        String sql = "insert into account values (sq_account.nextval,?,?,?,?,?,?)";
        Object[] objects=new Object[6];
        objects[0]=account.getDealType();
        objects[1]= account.getPetId();
        objects[2]= account.getSellerId();
        objects[3]= account.getBuyerId();
        objects[4]= account.getPrice();
        Timestamp timestamp = new Timestamp(account.getDealTime().getTime());
        objects[5]= timestamp;
        int update = update(sql, objects);
        close(resultSet,statement,connection);
        return update;
    }
}
